package org.hot100_2;

import org.leetcode.TreeNode;

public class leetcode98 {

    TreeNode pre= null;
    public boolean isValidBST(TreeNode root) {
        return inorder(root);
    }

    //中序遍历
    private boolean inorder(TreeNode root){
        if (root==null){
            return true;
        }

        //左
        boolean leftIsValid = inorder(root.left);

        if (!leftIsValid){
            return false;
        }
        //中
        if (pre!=null && pre.val>=root.val){
            return false;
        }

        pre = root;

        //右
        boolean rightIsValid = inorder(root.right);

        if (!rightIsValid){
            return false;
        }

        return true;
    }
}

